package jmind.core.support;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class DocumentUtil {

	private static Map<String, Document> map = new HashMap<String, Document>();

	public static Document getDoc(String name) {
		if (map.containsKey(name)) {
			return map.get(name);
		}
		synchronized (map) {
			return map.put(name, initDoc(name));
		}
	}

	private static Document initDoc(String name) {
		try {
			return Jsoup.parse(DocumentUtil.class.getClassLoader().getResourceAsStream(name), "UTF-8", "");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
